home *** CD-ROM | disk | FTP | other *** search
- /*
- ** File: MacWT.c
- **
- ** Written by: Bill Hayden
- ** Nikol Software
- **
- ** Copyright © 1995 Nikol Software
- ** All rights reserved.
- */
-
-
-
- #include <stdio.h>
- #include "MacWT.h"
- #include "Music.h"
- #include "FileUtils.h"
- #include "StringUtils.h"
- #include "Failure.h"
- #include "Constants.h"
- #include "framebuf.h"
- #include "graphics.h"
- #include "fixed.h"
- #include "world.h"
- #include "view.h"
- #include "object.h"
- #include "render.h"
- #include "worldfile.h"
- #include "error.h"
- #include "input.h"
-
-
-
-
- static void GetScreenSize(short *width, short *height);
-
-
- OSErr gMusicErr;
- fixed start_x = 0, start_y = 0;
- World *w;
- Object *me, *him;
- View *view;
-
-
-
-
- /*****************************************************************************/
-
-
-
-
- void InitMacWT(void)
- {
- unsigned char **versRsrc;
- Graphics_info *ginfo;
- PhysicsModel pm;
- FILE *fp;
- short width, height;
- extern double gravity;
- extern Intent gIntent;
- Rect r;
- CursHandle curs;
- RgnHandle GrayRgn = LMGetGrayRgn() ;
-
-
- // remember the version
-
- if (!gWorldFile[0])
- if (!SelectWorldFile(gWorldFile))
- ExitToShell();
-
- //GetFilenameFromPathname(gWorldFile, WindowTitle);
-
- if ((versRsrc = (unsigned char **)Get1Resource('vers', 1)) != 0)
- pcpy(gWTVersion, *versRsrc + 6);
-
- /* Open MacWT windows (well, dialogs)... */
-
- gWindow = GetNewDialog(rWindowID, nil, (WindowRef)-1);
- if (!gWindow)
- Fail(ResError(), __FILE__, __LINE__, TRUE);
-
- gBackgroundWindow = GetNewDialog(rBackgroundWindowID, nil, (WindowRef)gWindow);
- if (!gBackgroundWindow)
- Fail(ResError(), __FILE__, __LINE__, TRUE);
-
- UnionRect( &((**GrayRgn).rgnBBox), &(qd.screenBits.bounds), &r ) ;
-
- MoveWindow( (WindowRef)gBackgroundWindow, r.left, r.top, false ) ;
- SizeWindow( (WindowRef)gBackgroundWindow, r.right-r.left, r.bottom-r.top, true ) ;
-
- ShowWindow((WindowRef)gWindow);
- SelectWindow( (WindowRef)gWindow ); /* bring fore wind to front */
-
- GetScreenSize(&width, &height);
-
- SetPortWindowPort(gWindow);
- TextFont(geneva);
- TextSize(9);
- TextFace(bold);
-
- // wt.c start
-
- gMusicErr = LoadMusicDriver();
-
- ginfo = InitGraphics(width, height);
-
- InitRenderer(ginfo->width, ginfo->height);
- SetMem(&gIntent, 0, sizeof(gIntent));
-
- p2c(gWorldFile);
-
- if ((fp = fopen((char *)gWorldFile, "r")) == NULL)
- {
- fatal_error("The file “%s” could not be found.", (char *)gWorldFile);
- return;
- }
-
- curs = GetCursor(watchCursor);
- SetCursor(*curs);
-
- w = read_world_file(fp);
- fclose(fp);
-
- pm = (PhysicsModel)Get1Resource('Phys', 128);
-
- if (pm)
- {
- HLock((Handle)pm);
- gravity = -(*pm)->gravity / 100.0;
- me = new_object( (*pm)->mass,
- (*pm)->xsize / 10.0,
- (*pm)->ysize / 10.0,
- (*pm)->height / 10.0,
- (*pm)->drag / 100.0); // load physics model
- HUnlock((Handle)pm);
- ReleaseResource((Handle)pm);
- }
- else
- me = new_object(70.0, 1.5, 1.5, 1.8, 0.6); // load in default physics model values
-
- him = new_object(70.0, 1.5, 1.5, 3.0, 0.6);
-
-
- /* setup view */
- view = CreateView(FIXED_HALF_PI, FIXED_ONE);
-
- add_object(w, me);
- object_set_position(me, FIXED_TO_FLOAT(start_x), FIXED_TO_FLOAT(start_y), 0.0);
-
- add_object(w, him);
- object_set_position(him, 3.0, 5.0, 0.0);
-
- AddFrame(him, ":textures:Man1.pictr");
- AddFrame(him, ":textures:Man2.pictr");
- AddFrame(him, ":textures:Man3.pictr");
- AddFrame(him, ":textures:Man4.pictr");
-
- him->triggerticks = 25L;
-
- SetFrame(him, 0);
-
- SetCursor(&qd.arrow);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- void DisposeMacWT(void)
- {
- EndGraphics();
-
- if (!gMusicErr)
- {
- StopMusic();
- DisposeMusicDriver();
- }
- }
-
-
-
- /*****************************************************************************/
-
-
-
- static void GetScreenSize(short *width, short *height)
- {
- short ScreenSize, iType;
- Handle iHandle;
- extern Rect gDestinationRect;
- extern Rect gInformationRect;
-
-
- ScreenSize = Alert(rScreenSize, nil);
-
- GetDialogItem( gWindow, ScreenSize, &iType, &iHandle, &gDestinationRect );
- GetDialogItem( gWindow, 5, &iType, &iHandle, &gInformationRect );
-
- *width = gDestinationRect.right - gDestinationRect.left;
- *height = gDestinationRect.bottom - gDestinationRect.top;
- }
-
-
-